# -*- coding: UTF-8 -*-
__author__ = 'BK'
import base64
import poplib
import email
import string

#POP3协议

host = 'pop.qq.com'
username = '412203179@qq.com'
password = ''

pop_conn = poplib.POP3_SSL(host)
pop_conn.user(username)
pop_conn.pass_(password)

ret = pop_conn.stat()

hdr,message,octet = pop_conn.retr(32)

mail=email.message_from_string(string.join(message,'\n'))

# print email.Header.decode_header(mail['subject'])[0][0]
# print email.Header.decode_header(mail['X-QQ-STYLE'])[0][0]
# print email.Header.decode_header(mail['Mime-Version'])[0][0]
# print email.Header.decode_header(mail['Content-Type'])[0][0]
# print email.Header.decode_header(mail['Content-Transfer-Encoding'])[0][0]
# print unicode(email.Header.decode_header(mail['subject'])[0][0],'utf8')
# print email.Header.decode_header(mail['subject'])[0][0]
print unicode(email.Header.decode_header(mail['from'])[0][0],'utf8')
# print email.Header.decode_header(mail['from'])[0][0]

# for i in mail.walk():
#     print i.get_payload(decode=True)

pop_conn.quit()

